import axios from "axios";

const houseBaseUrl= "http://localhost:8082";
const houseRequest={
    loadHouses(house,callBack){
        let url = houseBaseUrl + "/house/list?";
        if(house){
            if(house.houseEncode){
                url += "&houseEncode=" + house.houseEncode;
            }
            if(house.houseName){
                url += "&houseName=" + house.houseName;
            }
        }
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    insert(house,callBack){
        let url = houseBaseUrl + "/house/insert";
        axios.post(url,house)
            .then(res=>{
                callBack(res.data);
            })
    },
    update(house,callBack){
        let url  = houseBaseUrl + "/house/update";
        axios.put(url,house)
            .then(res=>{
                callBack(res.data);
            })
    },
    selectById(houseId,callBack){
        let url = houseBaseUrl + "/house/selectById?houseId=" + houseId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    delete(houseId,callBack){
        let url = houseBaseUrl + "/house/delete?houseId=" + houseId;
        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    }
}

export default houseRequest;
